﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using dhDataAcess.baseBLL;
using dhDataAcess.produceDAL.Stock;
using dhDataAcess.dataAcess.stockDataSetTableAdapters;
using dhDataAcess.dataAcess.baobiaoDataSetTableAdapters ;
using dhDataAcess.dataAcess;
using System.Data.SqlClient;
using dhDataAcess.produceLinq.StockLinq;

namespace dhSystemBLL.produceBLL
{
 public  class productStockBLL
    {

     private V_productStockTableAdapter _V_productStockAdapter = null;
     private V_productStockTableAdapter V_productStockAdapter
        {
            get
            {
                if (_V_productStockAdapter == null) _V_productStockAdapter = new V_productStockTableAdapter();
                return _V_productStockAdapter;

            }
        }
     private productStockTableAdapter _productStockAdapter = null;
     private productStockTableAdapter  productStockAdapter
        {
            get
            {
                if (_productStockAdapter == null) _productStockAdapter = new  productStockTableAdapter();
                return _productStockAdapter;

            }
        }

        /// <summary>
     /// 查询胚带库存表
        /// </summary>
        /// <returns></returns>

     public stockDataSet.productStockDataTable getproductStockAll()
        {
            try
            {
                return productStockAdapter.GetDataproductStockAll();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
        }
     /// <summary>
     /// 查询胚带库存表
     /// </summary>
     /// <returns></returns>

     public baobiaoDataSet.V_productStockDataTable getV_productStockAll()
     {
         try
         {
             return V_productStockAdapter.GetDataV_productStockALL ();
         }
         catch (Exception ex)
         {
             throw new Exception(ex.Message.ToString());
         }
     }

        /// <summary>
        /// 根据产品名称查询胚带库存表
        /// </summary>
        /// <param name="groupNum"></param>
        /// <returns></returns>
     public stockDataSet.productStockDataTable getproductStockAllBypname(string pname)
        {
            try
            {
                return productStockAdapter.GetDataproductStockBypname(pname);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message.ToString());
            }
        }

        /// <summary>
        /// 插入信息
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>

     public int productStockInsert(productStockModel row)
        {
            int i = 0;
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;
            try
            {
                tn = conn.BeginTransaction();
                productStockDAL productStock = new productStockDAL(tn, conn);
                productStock.productStockInsert(row);
                tn.Commit();
                return i;
            }
            catch (SqlException ex)
            {
                tn.Rollback();
                if (ex.Number == 2627)
                {
                    throw new Exception("这个主键已经存在");
                }


                throw new Exception(ex.Number.ToString() + ex.Message.ToString());

            }
            catch (Exception ex)
            {
                tn.Rollback();
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                conn.Close();
            }
        }
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>

     public int productStockUpdate(productStockModel row)
        {
            int i = 0;
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;
            try
            {
                tn = conn.BeginTransaction();
                productStockDAL productStock = new productStockDAL(tn, conn);
                productStock.productStockUpdate(row);
                tn.Commit();
                tn.Commit();
                return i;

            }
            catch (Exception ex)
            {
                tn.Rollback();
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                conn.Close();
            }
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="itemNum"></param>
        /// <returns></returns>

     public int productStockDel(string recordID)
        {
            int i = 0;
            SqlConnection conn = dataConn.connOpen();
            SqlTransaction tn = null;
            try
            {
                tn = conn.BeginTransaction();
                productStockDAL productStock = new productStockDAL(tn, conn);
                productStock.productStockDel(recordID);
                tn.Commit();
                return i;
            }
            catch (Exception ex)
            {
                tn.Rollback();
                throw new Exception(ex.Message.ToString());
            }
            finally
            {
                conn.Close();
            }
        }

    }
}
